<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #main {
            width: 200px;
            height: 200px;
            background-color: deepskyblue;
        }
    </style>
</head>

<body>
    <div id="main"></div>

    <script>
        //获取元素
        const oDiv = document.getElementById("main")

        //核心代码
        function center(e){
            console.log("center");
            console.log(e);
            console.log(this);
        }

        //触发事件
        oDiv.onmousemove = throttle(center , 500)

        //节流函数
        function throttle(center , timer){
            //上一次的时间
            let lastTime = 0
            //真正的事件函数
            return function (e) {
                //新的时间
                let nowTime = Date.now()
                //书写一个看门狗
                if(nowTime - lastTime < timer){
                    return
                }
                lastTime = nowTime
                center.call(this , e)
            }
        }




    </script>
</body>

</html>